package com.example.week12_networkprogramming;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBUtil {
    private static String user="root";
    private static String password="mypassword";
    private static Connection getConn(String dbName){
        Connection connection=null;
        try {
            Class.forName("com.mysql.jdbc.dbName");
            String url="jdbc:mysql://192.168.0.104:3306/"+dbName;
            connection= DriverManager.getConnection(url,user,password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return connection;
    }

    public static ResultSet queryReader(String read_num){
        ResultSet rs=null;
        Connection connection=getConn("library");
        if (connection!=null){

            try {
                PreparedStatement ps;
                Statement smt=connection.createStatement();
                String sql="select * from readers where reader_number LIKE'%"+read_num+"%'";
                rs=smt.executeQuery(sql);
                //connection.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        return rs;
    }
}
